<?php
/**
 * Created by PhpStorm.
 * User: dwlw
 * Date: 2018/5/7
 * Time: 10:25
 */
namespace app\admin\controller;

use app\admin\model\User;
class Users extends Base{

    public function lst(){

        //获取用户信息
        $user = new User();
        $users = $user->get_user();
        $this->assign('users',$users);
        return $this->fetch();
    }

    public function add(){
        if ($this->request->isPost()){
            $this->get_add();
        }else{
            //获取分所数据
            $user = new User();
            //获取权限模板列表
            $auth = new \app\admin\model\Auth();
            $auth_model = $auth->get_auth_model('auth_model = 1');
            $this->assign('auth_model',$auth_model);
            return $this->fetch();
        }
    }

    public function edit(){
        if ($this->request->isPost()){
            $this->get_edit();
        }else{
            //获取分所数据
            $user = new User();
            $id = input();
            $query = new \think\db\Query();
            $users = $query->table('d_user')->where('id',$id['id'])->find();
            $this->assign('branch',[]);
            $this->assign('users',$users);
            $this->assign('ids',$id);
            //获取get提交的id查询出值
            return $this->fetch();
        }

    }

    //处理add提交数据
    public function get_add(){
        $datas = input('post.');
        $user = new User();
        $inserts = $user->get_adds($datas);
        if($inserts==999){
            $this->error('请按要求填写后提交，或用户名重复。');
        }else{
            $this->success('新增成功', 'Users/lst');
        }
    }

    //处理edit提交数据
    public function get_edit(){
        $datas = input('post.');
        $ids = $datas['ids'];
        unset($datas['ids']);
        $user = new User();
        $inserts = $user->get_edits($datas,$ids);
        if($inserts==999){
            $this->error('请按要求填写后提交，或用户名重复。');
        }else{
            $this->success('修改成功', '/admin/users/edit/id/'.$ids.'.html');
        }
    }

    public function details(){
        //获取用户信息
        return $this->fetch();
    }

    public function tree(){
        //获取用户信息
        return $this->fetch();
    }
}